package com.suray.system.run.data;

import com.suray.system.run.core.BaseInfo;

import java.util.Date;
import java.util.Objects;

public class DeviceTaskInformation extends BaseInfo {

    /**
     * 当天执行任务的时间
     * ms
     */
    private long execTodayTaskTime;

    /**
     * 当前日期
     * 记录当前数据的日期
     */
    private Date curDate;

    /**
     * 执行任务的总时间
     * ms
     */
    private long execAllTaskTime;

    /**
     * 执行的任务数量
     */
    private int execTaskNum;

    public DeviceTaskInformation() {
        execTodayTaskTime = 0;
        curDate = new Date(System.currentTimeMillis());
        execAllTaskTime = 0;
        execTaskNum = 0;
    }

    public Date getCurDate() {
        return curDate;
    }

    public void setCurDate(Date curDate) {
        this.curDate = curDate;
    }

    public long getExecTodayTaskTime() {
        return execTodayTaskTime;
    }

    public void addExecTodayTaskTime(long execTodayTaskTime) {
        this.execTodayTaskTime += execTodayTaskTime;
    }

    public void clearExecTodayTaskTime() {
        this.execTodayTaskTime = 0;
    }

    public long getExecAllTaskTime() {
        return execAllTaskTime;
    }

    public void addExecAllTaskTime(long taskTime) {
        this.execAllTaskTime += taskTime;
    }

    public int getExecTaskNum() {
        return execTaskNum;
    }

    public void addExecTaskNum() {
        this.execTaskNum++;
    }

    /**
     * 是否同一天
     * @param date
     * @return
     */
    public boolean checkDate(Date date) {
        if ((curDate != null)
                && (curDate.getYear() == date.getYear()
                && curDate.getMonth() == date.getMonth()
                && curDate.getDay() == date.getDay()
        )) {
            return true;
        }

        return false;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DeviceTaskInformation that = (DeviceTaskInformation) o;
        return execTodayTaskTime == that.execTodayTaskTime &&
                execAllTaskTime == that.execAllTaskTime &&
                execTaskNum == that.execTaskNum &&
                Objects.equals(curDate, that.curDate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(execTodayTaskTime, curDate, execAllTaskTime, execTaskNum);
    }
}
